package com.xc.h05.controller.weichen;

import com.github.pagehelper.PageInfo;
import com.xc.h05.entity.Mytest;
import com.xc.h05.service.weichen.MyTestService;
import com.xc.h05.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("myTest")
public class MyTestController {
    @Autowired
    private MyTestService myTestService;
    @PostMapping("/add")
    public R add(@RequestBody Mytest mytest){
        int add = myTestService.add(mytest);
        if (add>0){
            return R.ok(mytest);
        }else {
            return R.error();
        }
    }
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable("id") int id){
        int delete = myTestService.delete(id);
        if (delete>0){
            return R.ok(delete);
        }else {
            return R.error();
        }
    }
    @PostMapping("/deletes")
    public R deletes(@RequestBody List<Integer> list){
        int deletes = myTestService.deletes(list);
        if (deletes>0){
            return R.ok(deletes);
        }else {
            return R.error();
        }
    }
    @PutMapping("/update")
    public R update(@RequestBody Mytest mytest){
        int update = myTestService.update(mytest);
        if (update>0){
            return R.ok(mytest);
        }else {
            return R.error();
        }
    }
    @GetMapping("/findByPage")
    public R findByPage(int pageNum, int pageSize, Mytest mytest){
        PageInfo<Mytest> pageInfo = myTestService.findByPage(pageNum, pageSize, mytest);
        return R.ok(pageInfo);
    }
    @GetMapping("/findByNicknamePage")
    public R findByNicknamePage(int pageNum, int pageSize,Mytest mytest){
        PageInfo<Mytest> pageInfo = myTestService.findByNicknamePage(pageNum, pageSize, mytest);
        return R.ok(pageInfo);
    }
    @GetMapping("/findByTestId/{testId}")
    public R findByTestId(@PathVariable("testId") int testId){
        List<Mytest> list = myTestService.findByTestId(testId);
        return R.ok(list);
    }
}
